<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('基金变量') }}</span>
    </div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:properties:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:properties:edit']"
          type="warning"
          icon="el-icon-save"
          size="mini"
          @click="saveHandle"
        >{{ $t('保存') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="fundPropertiesList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金变量')" align="center" prop="fundKey">
        <template slot-scope="scope">
          <span v-if="scope.row.id">{{ scope.row.fundKey }}</span>
          <el-input v-else v-model="scope.row.fundKey" type="textarea" maxlength="2000" class="fileTextarea" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金变量值')" align="center" prop="fundValue">
        <template slot-scope="scope">
          <el-input v-model="scope.row.fundValue" type="textarea" maxlength="2000" class="fileTextarea" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('描述')" align="center" prop="fundDescribe">
        <template slot-scope="scope">
          <el-input v-model="scope.row.fundDescribe" type="textarea" maxlength="2000" class="fileTextarea" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['fund:properties:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listFundProperties, delFundProperties, saveFundProperties } from '@/api/sass/kaihui/fund/fundProperties'

export default {
    components: {
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 基金变量表格数据
          fundPropertiesList: [],
          // 弹出层标题
          title: '基金变量',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              fundId: undefined,
              fundKey: undefined,
              fundValue: undefined,
              fundDescribe: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
  },
  methods: {
    /** 查询基金变量列表 */
    getList() {
        this.loading = true
      this.queryParams.fundId = this.$route.query.id
        listFundProperties(this.queryParams).then(response => {
            this.fundPropertiesList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },
    addHandle() {
      this.fundPropertiesList.push({})
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delFundProperties(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
            this.loading = false
        })
    },
    /** 保存按钮操作 */
    saveHandle() {
      const data = {
        'fundPropertiesList': this.fundPropertiesList,
        'fundId': this.$route.query.id
      }
      saveFundProperties(data).then(response => {
        console.log(response)
        this.queryHandle()
      })
    }
  }
}
</script>
